<!DOCTYPE html>
<html>

<head>
<title></title>
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">

<%include("/common/include.html"){}%>
<style type="text/css">
</style>
</head>

<body class="easyui-layout">
	<table id="upPriceTable" class="easyui-datagrid" style="height:100%;">
		
	</table>
	
	<form id="upPriceForm">
		<input id="priceIds" type="hidden" value="${price.ids! }" name="price.ids">
		<div id="tb" style="height:auto">
			价格表名称:<input id="priceName" class="easyui-textbox theme-textbox-radius" style="width: 38%;" value="${price.name! }">
		</div>
	</form>
	
	<script type="text/javascript">
		var $form = $('#upPriceForm');
	
		var submitNow = function($dialog, $grid, $tree, $pjq) {
			if (endEditing()){
				var priceName = $("#priceName").val();
				$("#upPriceForm").append("<input type='hidden' name='price.name' value='"+priceName+"'/>");
				var rows = $('#upPriceTable').datagrid('getChanges');
				var ii = 0;
				for(var i=0;i<rows.length;i++){
					var productIds = rows[i].ids;
					var name = rows[i].name;
					var putPrice = rows[i].putprice;
					var outPrice = rows[i].outprice;
					var ppIds = rows[i].ppids;
					if(outPrice != null &&outPrice != ''){
					if(putPrice==null||putPrice==''){
						putPrice = 0;
					}
					$("#upPriceForm").append("<input type='hidden' name='productPriceList["+ii+"].ids' value='"+ppIds+"'/>");
					$("#upPriceForm").append("<input type='hidden' name='productPriceList["+ii+"].productIds' value='"+productIds+"'/>");
					$("#upPriceForm").append("<input type='hidden' name='productPriceList["+ii+"].productName' value='"+name+"'/>");
					$("#upPriceForm").append("<input type='hidden' name='productPriceList["+ii+"].putPrice' value='"+putPrice+"'/>");
					$("#upPriceForm").append("<input type='hidden' name='productPriceList["+ii+"].outPrice' value='"+outPrice+"'/>");
					ii=ii+1;
					}
				}
			}
			
			var url = "${cxt!}/productPriceSet/updatePrice";
			$.post(url, sy.serializeObject($form), function(result) {
				if (result.code == '200') {
					$dialog.dialog('destroy');
					$tree.combobox('reload');
					$.slideMsg("修改成功！", $pjq);
					$grid.datagrid('reload');
					
				} else {
					$.alert($pjq, result.msg);
				}
			}, 'json');
		};
		var submitForm = function($dialog, $grid, $tree, $pjq) {
			submitNow($dialog, $grid, $tree, $pjq);
			// 					$form.isValid(function(isValied){
			// 						if(isValied){
			// 							submitNow($dialog, $grid, $pjq);
			// 						}
			// 					});
		};
		(function($){
			var priceIds = $("#priceIds").val();
			var param = {
						'_query.priceIds':priceIds
					};
			var organLevel = "${organ.level! }"
				var columns;
				if(organLevel == '1'){
					columns = [[
						  		{field:'ids',title:'ids',width:100,align:'center', hidden:true},
						  		{field:'ppids',title:'ppids',width:100,align:'center', hidden:true},
						  		{field:'probh',title:'编号',width:100,align:'center'},
						  		{field:'name',title:'名称',width:100,align:'center'},
						  		{field:'type',title:'类型',width:100, align:'center'},
						  		{field:'putprice',title:'入库价(元)',width:80, align:'center',
						  			editor:{type:'numberbox',options:{precision:1}}
						  		},
						  		{field:'outprice',title:'出库价(元)',width:80, align:'center',
						  			editor:{type:'numberbox',options:{precision:1}}
						  		}
						      ]];
				}else{
					columns = [[
						  		{field:'ids',title:'ids',width:100,align:'center', hidden:true},
						  		{field:'ppids',title:'ppids',width:100,align:'center', hidden:true},
						  		{field:'probh',title:'编号',width:100,align:'center'},
						  		{field:'name',title:'名称',width:100,align:'center'},
						  		{field:'type',title:'类型',width:100, align:'center'},
						  		{field:'putprice',title:'入库价(元)',width:80, align:'center'},
						  		{field:'outprice',title:'出库价(元)',width:80, align:'center',
						  			editor:{type:'numberbox',options:{precision:1}}
						  		}
						      ]];
				}

			$('#upPriceTable').datagrid({
				cls: "theme-datagrid",
				toolbar: '#tb',
				singleSelect: true,
				rownumbers: true, //显示序号
				pagination: true,
				pageSize: 30,
				url: "${cxt!}/productPriceSet/productPriceList",
				queryParams: param,
			    method: 'post',
				columns:columns,
				onLoadSuccess:function(){
		        	
				},
				onClickRow:function(index, rowData){
					if (editIndex != index){
						if (endEditing()){
							$('#upPriceTable').datagrid('selectRow', index)
									.datagrid('beginEdit', index);
							editIndex = index;
						} else {
							$('#upPriceTable').datagrid('selectRow', editIndex);
						}
					}
				}
			});
		})(jQuery);
	</script>
	<script type="text/javascript">
		var editIndex = undefined;
		function endEditing(){
			if (editIndex == undefined){return true}
			if ($('#upPriceTable').datagrid('validateRow', editIndex)){
				$('#upPriceTable').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
		}
	</script>

</body>
</html>